using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace Colman.Rpg.Npc
{
    /// <summary>
    /// A tile in the NPC world.
    /// </summary>
    public class Tile : PictureBox
    {
        private static Dictionary<TileType, Image> images;

        static Tile()
        {
            images = new Dictionary<TileType, Image>();
            images.Add(TileType.Grass, Properties.Resources.NpcGrass);
            images.Add(TileType.Monster, Properties.Resources.NpcMonster);
            images.Add(TileType.Player, Properties.Resources.NpcHero);
            images.Add(TileType.Rock, Properties.Resources.NpcRock);
            images.Add(TileType.Tree, Properties.Resources.NpcLog);
        }

        /// <summary>
        /// Creates a new instance of <see cref="Tile" />.
        /// </summary>
        public Tile()
        {
            this.Size = new Size(32, 32);
            this.SetStyle(ControlStyles.FixedHeight, true);
            this.SetStyle(ControlStyles.FixedWidth, true);
            this.SetStyle(ControlStyles.Opaque, true);

            this.Type = TileType.Grass;
        }

        /// <summary>
        /// Performs the work of setting the specified bounds of this control.
        /// </summary>
        /// <param name="x">The new <see cref="Control.Left"/> property value of the control.</param>
        /// <param name="y">The new <see cref="Control.Top"/> property value of the control.</param>
        /// <param name="width">The new <see cref="Control.Width"/> property value of the control.</param>
        /// <param name="height">The new <see cref="Control.Height"/> property value of the control.</param>
        /// <param name="specified">A bitwise combination of the <see cref="BoundsSpecified"/> values.</param>
        protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
        {
            // Maintain the size of tiles.
            width = 32; height = 32;

            base.SetBoundsCore(x, y, width, height, specified);
        }

        #region TileType Type { get; set; } (type)
        private TileType type;

        /// <summary>
        /// Gets or sets the tile's type.
        /// </summary>
        public TileType Type
        {
            [System.Diagnostics.DebuggerStepThrough]
            get
            {
                return this.type;
            }
            set
            {
                if (this.type != value || this.Image == null)
                {
                    this.type = value;

                    this.Image = images[value];
                }
            }
        }
        #endregion
    }
}
